Skip to content

Add preview mode for update actions#1945

Open
MrAnayDongre wants to merge 2 commits into
cocoindex-io:mainfrom
MrAnayDongre:anay/issue-1890-preview-clean
Open

Add preview mode for update actions#1945
MrAnayDongre wants to merge 2 commits into
cocoindex-io:mainfrom
MrAnayDongre:anay/issue-1890-preview-clean

Conversation

@MrAnayDongre
Copy link
Copy Markdown
Contributor

@MrAnayDongre MrAnayDongre commented May 6, 2026

Summary

Adds preview mode for update actions in both the Python API and CLI.

With preview enabled, CocoIndex computes the same target actions as a normal update, but does not apply them to real targets and does not commit internal tracking state.

Closes #1890.

API and CLI

Preview is supported in:

  • App.update(..., preview=True)
  • App.update_blocking(..., preview=True)
  • cocoindex update --preview

For the Python API, preview returns the planned action objects.
For the CLI, preview prints the planned actions.

Implementation

This reuses the existing planning path instead of introducing a separate planner.

In preview mode:

  • reconciliation still runs through pre_commit(...)
  • planning runs in a standalone write transaction
  • that transaction is dropped without commit
  • sink.apply(...) is skipped
  • the later commit phase is skipped

This keeps preview aligned with normal update behavior while remaining read-only.

First pass scope

This first pass supports flat / leaf target actions only.

If a target requires child target providers, preview fails clearly instead of returning partial output.

CLI behavior

Added:

  • cocoindex update ... --preview

Tests

Added coverage for:

  • sync preview returns actions without writing
  • async preview returns actions without writing
  • preview rejects child target providers
  • CLI preview prints planned actions

Validation

Ran locally:

  • cargo fmt --check
  • cargo test
  • uv run mypy
  • uv run pytest python/tests/core -q
  • uv run pytest python/tests/internal -q
  • uv run pytest python/tests/cli/test_cli.py -q

MrAnayDongre and others added 2 commits May 5, 2026 22:15
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@MrAnayDongre MrAnayDongre marked this pull request as ready for review May 7, 2026 22:16
@badmonster0 badmonster0 requested a review from georgeh0 May 25, 2026 18:38
@badmonster0
Copy link
Copy Markdown
Member

@georgeh0 can help take a look!

Copy link
Copy Markdown
Member

@georgeh0 georgeh0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review!

Most parts look good. A few minor comments. Please also merge with latest and resolve conflict. Thanks!

def test_preview_prints_actions(self) -> None:
"""update --preview should print planned actions without writing."""
result = run_cli("update", "./flat_target_app.py", "--preview")
assert "Preview: planned target actions" in result.stdout
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also check the specific actions really printed out in the output?

Comment on lines +123 to +124
options.preview,
preview_collector.clone(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to combine these two, i.e. everywhere we can use preview_collector.is_some() to determine if it's under preview mode.

We can even consider using Option<PreviewActionCollector<Prof>> to replace the preview: bool field in AppUpdateOptions. The update() API will remain returning a single handle (PreviewCollector is more like a side channel output, so keeping the return value a simple handle is attractive).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] support shadow run / preview

3 participants